/**
 * gislin 2017年7月14日
 */
package com.btcode.db.wherefilter;

import com.btcode.db.sqlparameter.SQLParameterList;
import java.util.ArrayList;
import java.util.List;

/**
 * sql操作组
 *
 * @author gislin 2017年7月14日
 */
public class WhereFilterMulit implements IWhereFilter {

    List<WhereFilterSingle> filters = new ArrayList<WhereFilterSingle>();

    public WhereFilterMulit addOperation(WhereFilterSingle operation) {
        filters.add(operation);
        return this;
    }

    @Override
    public String getWhereText() {

        StringBuffer strBuffer = new StringBuffer(" ( ");

        for (int i = 0; i < filters.size(); i++) {
            WhereFilterSingle filter = filters.get(i);
            strBuffer.append(filter.getWhereText());

            if (i < filters.size() - 1) {
                strBuffer.append(" AND ");
            }
        }

        strBuffer.append(" ) ");

        return strBuffer.toString();
    }

    @Override
    public SQLParameterList getParameterList() {
        SQLParameterList parameters = new SQLParameterList();

        for (WhereFilterSingle filter : filters) {
            parameters.putAll(filter.getParameterList());
        }

        return parameters;
    }

}
